<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form divClass" v-if="headerShow">
        <div>
          <a-form
            size="small"
            :model="dataForm"
            layout="inline"
            label-align="right"
            :label-col-props="{ span: 8 }"
            :wrapper-col-props="{ span: 16 }"
          >
            <CorporateSectorCascader
              ref="cascaderRef"
              :configCascader="configCascader"
              @changeCascader="changeCascader"
              :style="{ width: '200px' }"
            />

            <a-form-item label-col-flex="65px" label="仓库">
              <a-select
                popup-container="html"
                style="width: 200px"
                class="bacClass"
                placeholder=""
                v-model="searchData.wh"
                allow-clear
              >
                <a-option v-for="item in whList" :value="item.id">
                  {{ item.warehouseName }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item label-col-flex="80px" label="拆纱单号">
              <a-input
                allow-clear
                :style="{ width: '200px' }"
                class="bacClass"
                v-model="pageData.disassembleCode"
              />
            </a-form-item>
            <a-form-item v-if="isIDs == 1" label-col-flex="80px" label="拆纱类型">
              <a-select
                popup-container="html"
                style="width: 200px"
                class="bacClass"
                v-model="pageData.orderType"
              >
                <a-option :value="0">拆纱单</a-option>
                <a-option :value="1">发纱单</a-option>
                <a-option :value="2">全部</a-option>
              </a-select>
            </a-form-item>
            <a-form-item v-if="isIDs == 2" label-col-flex="80px" label="审核状态">
              <a-select
                popup-container="html"
                style="width: 200px"
                class="bacClass"
                v-model="pageData.empState"
                allow-clear
              >
                <a-option :value="2">已审核</a-option>
                <a-option :value="1">未审核</a-option>
              </a-select>
            </a-form-item>
            <a-form-item v-if="isIDs == 2" label-col-flex="65px" label="日期">
              <a-range-picker
                popup-container="html"
                class="bacClass"
                v-model="rangeValue"
                style="width: 300px"
                @change="changes111"
              />
            </a-form-item>
          </a-form>
        </div>
      </div>
      <div class="my-tool-bar">
        <Toolbar
          v-if="isIDs == 1"
          :items="['查询', '选择拆纱工']"
          @select="selectHandler"
          @selectcsg="selectcsg"
        >
        </Toolbar>
        <Toolbar v-else :items="['查询', '审核']" @select="selectHandler1" @audit="audit">
        </Toolbar>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up
            v-if="headerShow"
            @click="headerShow = false"
            :strokeWidth="2"
            :size="18"
          />
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18" />
        </a-divider>
      </div>
    </template>
    <template #pageTabel>
      <a-tabs :lazy-load="true" :justify="true" @change="changeTabs">
        <a-tab-pane title="待处理" :key="1">
          <a-spin
            :loading="pageData.pageLoading"
            tip="加载中"
            dot
            style="height: 100%; width: 100%; z-index: 999"
          >
            <AgGridVuesCopys
              :rowHeight="33"
              :headerHeight="33"
              rowSelection="multiple"
              :suppressDragLeaveHidesColumns="true"
              @grid-ready="gridReady"
              style="height: calc(100% - 45px)"
              @columnVisible="onColumnVisible"
              @columnResized="onColumnResized"
              @columnMoved="onColumnMoved"
              :defaultColDef="defaultColDef"
              class="ag-theme-alpine"
              :rowData="table.dataList"
              :columnDefs="tc1"
              :localeText="localeText1"
              :suppressCopyRowsToClipboard="true"
            >
            </AgGridVuesCopys>
            <paginationCopys
              :total="total"
              show-total
              show-jumper
              show-page-size
              @change="PageSize"
              @page-size-change="change1"
              style="justify-content: center"
              :page-size="pagination.pageSize"
              :current="pagination.page"
              :page-size-options="pagingList1"
            />
          </a-spin>
        </a-tab-pane>
        <a-tab-pane title="已处理" :key="2">
          <a-spin
            :loading="pageData.pageLoading"
            tip="加载中"
            dot
            style="height: 100%; width: 100%; z-index: 999"
          >
            <AgGridVuesCopys
              :rowHeight="33"
              :headerHeight="33"
              rowSelection="multiple"
              :suppressDragLeaveHidesColumns="true"
              @grid-ready="gridReady2"
              style="height: calc(100% - 45px)"
              @columnResized="onColumnResized2"
              @columnMoved="onColumnMoved2"
              @columnVisible="onColumnVisible2"
              :defaultColDef="defaultColDef"
              class="ag-theme-alpine"
              :rowData="tableDataList"
              :columnDefs="tc2"
              :localeText="localeText1"
              :suppressCopyRowsToClipboard="true"
            >
            </AgGridVuesCopys>
            <paginationCopys
              :total="total"
              show-total
              show-jumper
              show-page-size
              @change="PageSize"
              @page-size-change="change1"
              style="justify-content: center"
              :page-size="pagination2.pageSize"
              :current="pagination2.page"
              :page-size-options="pagingList1"
            />
          </a-spin>
        </a-tab-pane>
      </a-tabs>
    </template>

    <a-modal v-model:visible="visiblecg" :width="800" :unmount-on-close="true" :draggable="true">
      <template #title> 选择拆纱工 </template>
      <a-form :model="pageData" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 18 }">
        <!-- <a-cascader class="bacClass" v-model="pageData.firmId2" :options="pageData.firmList2" @focus="getFirmGroup"
            @change="changeFrim" :value-key="pageData.firmId2" allow-clear   /> -->
        <CorporateSectorCascader
          ref="corpSeeleFrim"
          :configCascader="configCascader1"
          @changeCascader="changeCascader1"
        />
        <a-form-item label="部门" field="firmId">
          <a-cascader
            class="bacClass"
            v-model="bumen"
            :options="bumenlist"
            @focus="getbumen"
            @change="changebumen"
            :value-key="bumen"
            allow-clear
            popup-container="html"
          />
        </a-form-item>
        <a-form-item field="ygName" label="员工">
          <a-select
            popup-container="html"
            @change="getempname"
            class="bacClass"
            v-model="pageData.ygName2"
            @focus="getYgName"
            :loading="loading6"
            :filter-option="false"
            :multiple="true"
            allow-clear
          >
            <a-option
              v-for="(item, index) in pageData.ygNameList2"
              :key="index"
              :value="item['id']"
            >
              {{ item['name'] }}
            </a-option>
          </a-select>
        </a-form-item>
      </a-form>
      <template #footer>
        <a-button type="primary" size="small" @click="Isok">保存</a-button>
      </template>
    </a-modal>

    <a-modal v-model:visible="pageDataCS.show" :width="800">
      <template #title> 修改拆纱工 </template>
      <a-form :model="pageDataCS" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 18 }">
        <a-form-item label="拆纱单号" field="firmId">
          <span style="margin-left: 20px">{{ pageDataCS.caishadanhao }}</span>
        </a-form-item>
        <a-form-item field="ygName" label="员工">
          <a-select
            popup-container="html"
            class="bacClass"
            v-model="pageDataCS.ygName"
            @click="getYgNameCS"
            :filter-option="false"
            :multiple="true"
            allow-clear
            @change="getempname2"
          >
            <a-option
              v-for="(item, index) in pageDataCS.ygNameList"
              :value="item['id'] + '#' + item['name'] + '#' + item['code']"
            >
              {{ item['name'] }}
            </a-option>
          </a-select>
        </a-form-item>
      </a-form>
      <template #footer>
        <a-button type="primary" size="small" @click="Isok2">保存</a-button>
      </template>
    </a-modal>
    <a-modal v-model:visible="visiblediolog" @ok="tanshenhe">
      <div>确认进行审核吗？</div>
    </a-modal>
  </pageTabelLayout>
</template>
<script lang="ts" setup>
  import { post, get } from '@/api/http'
  import {
    useTable,
    useRowKey,
    useTableColumn,
    usePagination,
    useRowSelection,
  } from '@/hooks/table'
  import printJS from 'print-js'
  import QrcodeVue from 'qrcode.vue'
  import ModalDialog from '@/components/ModalDialog.vue'
  import { ref, reactive, onMounted,onBeforeMount } from 'vue'
  import Toolbar from '@/components/Toolbar.vue'
  import { ModalDialogType } from '@/types/components'
  import { Message } from '@arco-design/web-vue'
  import PageTabelLayout from '@/components/pageTabelLayout.vue'
  import WHService, { Warhouse, CompanyList, WhTypeField } from '@/service/wh'
  import WHStore from '@/store/modules/wh'
  import { localeText } from '@/api/aggridZw'
  import { pagingList } from '@/api/paging'
  import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
  import { saveOrUpdateGridState as saveOrUpdateGridState01 } from '@/hooks/useGridState'
  import { saveOrUpdateGridState as saveOrUpdateGridState02 } from '@/hooks/useGridState'
  import { slicing } from '@/utils/caseFrimAndSecRig'
  import dayjs from 'dayjs'
  interface whTypeField {
    id: number | string | undefined
    serialNo: number
    warehouseId: number
    field: number | string | undefined
    mustState: number
    defaultValue: string
    selectState: number
    englishName: string
    valueType: number
    valueTypeNum: number
    showState: any
    saFeiPrintNum: any
  }
  const dataForm1 = reactive<whTypeField>({
    id: '',
    serialNo: 1,
    warehouseId: 0,
    field: '',
    mustState: 0,
    defaultValue: '',
    selectState: 0,
    englishName: '',
    valueType: 1,
    valueTypeNum: 0,
    showState: [],
    saFeiPrintNum: '',
  })
  interface ClothInfo {
    disassembleCode: any
    id: any
    dutymachineCode: string | undefined
    machineCode: string | undefined
    planOrderCode: string | undefined
    remark: string | undefined
    weaveCode: string | undefined
    greyCode: string | undefined
    grayName: string | undefined
    customName: string | undefined
    storey: string | undefined
    employeeId: string | undefined
    employeeName: string | undefined
    dutymachineDate: string | undefined
    schedulStartDate: string | undefined
    schedulEndDate: string | undefined
    dutymachineStartDate: string | undefined
    dutymachineEndDate: string | undefined
    dutymachineState: number | undefined
    dispatchState: number | undefined
    monitorState: number | undefined
    monitor: string | undefined
    obsoleteState: number | undefined
    deleteState: number | undefined

    createName: string | undefined
    createTime: string | undefined
    updateName: string | undefined
    updateTime: string | undefined
  }

  const headerShow = ref<boolean>(true)
  const userInfo = ref<any>({})
  const total = ref(10)
  const page = ref(1)
  const size = ref(10)
  function PageSize(val: any) {
    if (isIDs.value == 1) {
      pagination.page = val
      doRefresh()
    } else {
      pagination2.page = val
      doRefresh2()
    }
  }
  function change1(val: any) {
    if (isIDs.value == 1) {
      pagination.pageSize = val
      doRefresh()
    } else {
      pagination2.pageSize = val
      doRefresh2()
    }
  }

  let id = ref(1)
  //查询 未处理
  function doRefresh() {
    pageData.pageLoading = true
    updateGridState01()
    post({
      url: 'planSingle/disassembleOrder/getPage',
      data: {
        page: pagination.page,
        size: pagination.pageSize,
        deleteState: 0,
        warehouseId: searchData.wh,
        firmId: searchData.firm,
        disassembleCode: pageData.disassembleCode,
        empState: 0,
        orderType: pageData.orderType == 2 ? undefined : pageData.orderType,
      },
    })
      .then(({ data, code }: any) => {
        if (code === 200) {
          // loadings.value = false
          // pagination.setTotalSize(data.total);
          // pageData.dataList = data.list
          table.handleSuccess(data.list)
          gridOption.value.setRowData(data.list)
          total.value = data.total
        }
      })
      .catch(console.log)
      .finally(() => {
        pageData.pageLoading = false
      })
  }

  const tableDataList = ref([])

  const rangeValue = ref([])
  const changes111 = (e: any) => {
    if (e == undefined || e == '') {
      rangeValue.value = ['', '']
    }
  }
  // 查询 已处理
  function doRefresh2() {
    var shuzuA = [] as any
    var shuzuB = [] as any
    var isnewaryy = [] as any
    pageData.pageLoading = true
    updateGridState02()
    post({
      url: 'planSingle/disassembleEmployee/getPageEmp',
      data: {
        page: pagination2.page,
        size: pagination2.pageSize,
        empState: pageData.empState != '' ? pageData.empState : null,
        warehouseId: searchData.wh,
        firmId: searchData.firm,
        // startFinishTime 开始时间  endFinishTime 结束时间
        startFinishTime: rangeValue.value[0],
        endFinishTime: rangeValue.value[1],
        rawmaterialCode: pageData.rawmaterialCode,
        disassembleCode: pageData.disassembleCode,
        // empState: 1
      },
    })
      .then(({ data, code }: any) => {
        if (code === 200) {
          var arrry = [] as any
          shuzuA = data.list
          data.list.map((o: any) => {
            var changdu = o.empList.length
            o.empList.map((d: any, index: any) => {
              if (index == 0) {
                o.empName = ''
              }
              if (index + 1 < changdu) {
                o.empName = o.empName + d.empName + '/'
              } else if (index + 1 == changdu) {
                o.empName = o.empName + d.empName
              }
            })
            arrry.push(o)
          })
          tableDataList.value = arrry
          //sessionStorage.setItem("shujuooo",JSON.stringify(arrry))
          //table.handleSuccess(data.list);
          //gridOption2.value.setRowData(data.list);
          total.value = data.total
          // gridOption2.value.setRowData(arrry);
          // total.value = data.total
          // shuzuB = res.data.list
          // isnewaryy = shuzuB.concat(shuzuA)
          // gridOption2.value.setRowData(isnewaryy)
          // post({
          //   url: 'planSingle/disassembleEmployee/getPageEmp',
          //   data: {
          //     page: pagination.page,
          //     size: pagination.pageSize,
          //     empState: 2,
          //     warehouseId: searchData.wh,
          //     // warehouseId: 628,
          //     rawmaterialCode: pageData.rawmaterialCode,
          //   },
          // }).then((res: any) => {
          //   shuzuB = res.data.list
          //   isnewaryy = shuzuB.concat(shuzuA)
          //   gridOption2.value.setRowData(isnewaryy)
          // })
        }
      })
      .catch(console.log)
      .finally(() => {
        pageData.pageLoading = false
      })
  }

  const { selectedRowKeys, onSelectionChange } = useRowSelection()
  const selectedRowKeysChecked = useRowSelection()
  const pagination = usePagination(doRefresh)
  const pagination2 = usePagination(doRefresh2)
  const table = useTable()
  const rowKey = useRowKey('id')
  const tableColumns = useTableColumn([
    {
      title: '公司',
      key: 'company',
      dataIndex: 'company',
      width: 150,
    },

    {
      title: '仓库',
      key: 'warehouseName',
      dataIndex: 'warehouseName',
      width: 200,
    },
    {
      title: '拆纱单号',
      key: 'disassembleCode',
      dataIndex: 'disassembleCode',
      width: 150,
    },
    {
      title: '拆纱单类型',
      key: 'orderType',
      dataIndex: 'orderType',
      width: 150,
    },
    {
      title: '原料编号',
      key: 'rawmaterialCode',
      dataIndex: 'rawmaterialCode',
      width: 150,
    },
    {
      title: '原料名称',
      key: 'rawmaterialName',
      dataIndex: 'rawmaterialName',
      width: 150,
    },
    {
      title: '纱批',
      key: 'yarnBatch',
      dataIndex: 'yarnBatch',
      width: 150,
    },
    {
      title: '纱牌',
      key: 'brandName',
      dataIndex: 'brandName',
      width: 150,
    },
    {
      title: '色号',
      key: 'colorCode',
      dataIndex: 'colorCode',
      width: 150,
    },
    {
      title: '色称',
      key: 'colorName',
      dataIndex: 'colorName',
      width: 200,
    },
    {
      title: '拆纱重量',
      key: 'disassembleWeight',
      dataIndex: 'disassembleWeight',
      width: 200,
    },
    {
      title: '拆纱单日期',
      key: 'createTime',
      dataIndex: 'createTime',
      width: 150,
    },
  ])
  let tc1: any[] = tableColumns.map((o) => {
    let obj = {
      headerName: o.title,
      field: o.key,
      pinned: o['fixed'],
      tooltipField: o.key,
    }
    if (o.dataIndex === 'orderType') {
      obj['resizable'] = false
      obj['sortable'] = false
      obj['width'] = '150px'
      obj['cellRenderer'] = {
        template: `<span>{{a == 0 ? '拆纱单' : '发纱单'}}</span>`,
        setup(props: any) {
          return {
            a: props.params.data.orderType,
          }
        },
      }
      obj['filterParams'] = {
        valueFormatter: function (params: any) {
          return params.value == '0' ? '拆纱单' : '发纱单'
        },
      }
    }
    return obj
  })
  let a1 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
  ]
  tc1 = a1.concat(tc1)

  const tableColumnsChecked = useTableColumn([
    {
      title: '拆纱单号',
      key: 'disassembleCode',
      dataIndex: 'disassembleCode',
      width: 150,
    },
    {
      title: '拆纱单类型',
      key: 'orderType',
      dataIndex: 'orderType',
      width: 150,
    },
    {
      title: '公司',
      key: 'firm',
      dataIndex: 'firm',
      width: 150,
    },

    {
      title: '仓库',
      key: 'warehouse',
      dataIndex: 'warehouse',
      width: 200,
    },
    {
      title: '原料编号',
      key: 'rawmaterialCode',
      dataIndex: 'rawmaterialCode',
      width: 150,
    },
    {
      title: '原料名称',
      key: 'rawmaterialName',
      dataIndex: 'rawmaterialName',
      width: 150,
    },
    {
      title: '纱批',
      key: 'yarnBatch',
      dataIndex: 'yarnBatch',
      width: 150,
    },
    {
      title: '纱牌',
      key: 'brandName',
      dataIndex: 'brandName',
      width: 150,
    },
    {
      title: '色号',
      key: 'colorCode',
      dataIndex: 'colorCode',
      width: 150,
    },
    {
      title: '色称',
      key: 'colorName',
      dataIndex: 'colorName',
      width: 200,
    },
    {
      title: '拆纱重量',
      key: 'disassembleWeight',
      dataIndex: 'disassembleWeight',
      width: 200,
    },
    {
      title: '审核状态',
      key: 'empState',
      dataIndex: 'empState',
      width: 150,
      fixed: 'right',
    },
    {
      title: '拆纱工',
      key: 'empName',
      dataIndex: 'empName',
      width: 150,
      fixed: 'right',
    },
    {
      title: '操作',
      key: 'actions2',
      dataIndex: 'actions2',
      slotName: 'actions2',
      width: 150,
      fixed: 'right',
    },
    {
      title: '日期',
      key: 'finishTime',
      dataIndex: 'finishTime',
      slotName: 'finishTime',
      width: 150,
      fixed: 'right',
    },
  ])
  let tc2: any[] = tableColumnsChecked.map((o) => {
    let obj = {
      headerName: o.title,
      field: o.key,
      pinned: o['fixed'],
      tooltipField: o.key,
    }
    //审核状态
    if (o.dataIndex === 'empState') {
      obj['resizable'] = false
      obj['sortable'] = false
      ;(obj['lockPosition'] = 'right'),
        (obj['width'] = '110px'),
        (obj['cellRenderer'] = {
          template: `<a-space>
                        <el-tag  type="success" v-if="a==2" >已审核</el-tag>
                         <el-tag  type="success" v-if="a==1" >未审核</el-tag>
                       
                        </a-space>`,
          setup(props: any) {
            return {
              a: props.params.data.empState,
            }
          },
        })
      obj['filterParams'] = {
        valueFormatter: function (params: any) {
          return params.value == '1' ? '未审核' : params.value == '2' ? '已审核' : ''
        },
      }
    }

    //操作
    if (o.slotName === 'actions2') {
      obj['resizable'] = false
      obj['filter'] = false
      obj['sortable'] = false
      obj['lockPosition'] = 'right'
      obj['width'] = '100px'
      obj['cellRenderer'] = {
        template: `<a-popconfirm content="确认进行反审?" @ok="m">
                  <a-button size="small"  type="primary" status="warning" v-if="a==2" >反审</a-button>
                </a-popconfirm>
                <a-button  size="small" type="primary"  status="success" v-if="a==1" @click="c">修改</a-button>`,
        setup(props: any) {
          const m = () => {
            fanshen(props.params.data)
          }
          return {
            m,
            a: props.params.data.empState,
            c: () => {
              pageDataCS.show = true
              pageDataCS.caishadanhao = props.params.data.disassembleCode
              pageDataCS.ygName = props.params.data.empList.map((x: any) => {
                return x.empId + '#' + x.empName + '#' + x.empCode
              })
              if (props.params.data.empList.length > 0) {
                pageDataCS.data = props.params.data.empList[0]
              }
              getYgNameCS()
            },
          }
        },
      }
    }

    if (o.dataIndex === 'orderType') {
      obj['resizable'] = false
      obj['sortable'] = false
      obj['width'] = '150px'
      obj['cellRenderer'] = {
        template: `<span>{{a == 0 ? '拆纱单' : '发纱单'}}</span>`,
        setup(props: any) {
          return {
            a: props.params.data.orderType,
          }
        },
      }
      obj['filterParams'] = {
        valueFormatter: function (params: any) {
          return params.value == '0' ? '拆纱单' : '发纱单'
        },
      }
    }
    return obj
  })
  let a2 = [
    {
      showRowGroup: 'hide_def',
      headerName: '',
      checkboxSelection: true,
      headerCheckboxSelection: true,
      pinned: 'left',
      width: 50,
      resizable: false,
      filter: false,
      sortable: false,
      minWidth: 50,
      maxWidth: 50,
      lockPosition: 'left',
    },
  ]
  tc2 = a2.concat(tc2)
  const pageData: any = reactive({
    rawmaterialCode: '',
    planMaterialCode: '',
    orderNo: '',
    idList: '',
    sideTitle1: '修改打印张数',
    showAdd1: false,
    saFeiPrintNum: '',
    disPrintState: '',
    stockAllPieceNum: '',
    disassembleCode: '',
    showAdd: false,
    sideTitle: '新增值机派工',
    dutymachineCode: '',
    greyCode: '',
    grayName: '',
    planOrderCode: '',
    weaveCode: '',
    storey: '',
    dutymachineDate: [],
    dutymachineDate1: [],
    pageLoading: false,
    rHeight: '',
    dutymachineState: 0,
    checkHeadList: [],
    checkBodyList: [],
    bodyValueList: [],
    dataList: [],
    machineCodeOb: {},
    getList: [],
    dropDownList: [],
    tcDutymachineCode: '',
    tcStorey: '',
    tcDutymachineCodeList: [],
    tcStoreyList: [],
    ygType: '',
    ygName: '',
    ygTypeList: [],
    ygNameList: [],
    firmList: [],
    firmId: null,
    isShow: true,
    isShow1: true,
    filterList: [],
    editYgTime: [],
    employeeId: null,
    employeeName: '',
    NowDate: '',
    dutymachineId: null,
    dateStart: '',
    dateEnd: '',
    lists: [],
    firmList2: [],
    firmId2: '',
    ygName2: '',
    ygNameList2: [],
    newlist: [],
    empState: '',
    orderType: 0,
  })
  //下拉框得到焦点
  const focusSel = (val: any) => {
    selCxAll(val)
  }
  // const focusSel1 = (val: any) => {
  //     selCxAll1(val)
  // };
  //获取弹窗的公司部门组
  const getFirmGroup = () => {
    post({
      url: 'org/baCompany/getTreeCompanyOrDepartment',
    }).then(({ code, data }) => {
      if (code === 200) {
        pageData.firmList2 = data
        //sessionStorage.setItem("aoainio",JSON.stringify(pageData.firmList2))
      }
    })
  }
  //下拉数据
  const options = ref<any>(pageData.dropDownList)
  const loading = ref(false)
  const handleSearch = (value: any) => {
    if (value) {
      const ob = { dutymachineCode: value }
      loading.value = true
      selCxAll(ob)
      options.value = pageData.dropDownList
      loading.value = false
    } else {
      options.value = []
    }
  }
  const handleSearch1 = (value: any) => {
    if (value) {
      const ob = { greyCode: value }
      loading.value = true
      selCxAll(ob)
      options.value = pageData.dropDownList
      loading.value = false
    } else {
      options.value = []
    }
  }
  const handleSearch2 = (value: any) => {
    if (value) {
      const ob = { orderNo: value }
      loading.value = true
      selCxAll(ob)
      options.value = pageData.dropDownList
      loading.value = false
    } else {
      options.value = []
    }
  }
  const handleSearch3 = (value: any) => {
    if (value) {
      const ob = { planOrderCode: value }
      loading.value = true
      selCxAll(ob)
      options.value = pageData.dropDownList
      loading.value = false
    } else {
      options.value = []
    }
  }
  const handleSearch4 = (value: any) => {
    if (value) {
      // var val ={
      //     warehouseId:searchData.wh,
      //     key:"disassembleCode",
      //     value:value
      // };
      const ob = { disassembleCode: value }
      loading.value = true
      selCxAll(ob)
      options.value = pageData.dropDownList
      loading.value = false
    } else {
      options.value = []
    }
  }
  const handleSearch5 = (value: any) => {
    if (value) {
      const ob = { planMaterialCode: value }
      loading.value = true
      selCxAll1(ob)
      options.value = pageData.dropDownList
      loading.value = false
    } else {
      options.value = []
    }
  }
  //拆纱单号下拉框查询
  function selCxAll(val: any) {
    if (isIDs.value == 2) {
      post({
        url: 'planSingle/disassembleOrder/getDisassembleFieldValue',
        data: val,
      }).then(({ data, code }: any) => {
        if (code === 200) {
          pageData.dropDownList = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    } else {
      post({
        url: 'planSingle/planMaterial/getFieldValueByWarehouse',
        data: val,
      }).then(({ data, code }: any) => {
        if (code === 200) {
          pageData.dropDownList = data
        } else {
          Message.error({
            content: '查询失败！',
            duration: 5000,
          })
        }
      })
    }
  }
  // 补打纱飞下拉框查询
  function selCxAll1(val: any) {
    // console.log(val, 'vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv');
    if (isIDs.value == 2) {
      post({
        url: 'planSingle/disassembleOrder/getSaFeiPrintNum',
        data: val,
      }).then(({ data, code }: any) => {
        if (code === 200) {
          pageData.dropDownList = data
        }
      })
    }
  }
  onMounted(() => {
    doRefresh()
    doRefresh2()
  })
  onBeforeMount(() => {
    getUserInfo()
  })
  const getUserInfo = async()=>{
    let res = await post({
      url: 'admin/acl/user/findUserToken',
      data: {},
    })
      
        if (res.code === 200) {
          userInfo.value = res.data.data
        }
  }
  let isIDs: any = ref(1)
  // 已处理分页查询
  const selectHandler1 = () => {
    pagination2.page = 1
    loadings.value = true
    doRefresh2()
  }
  // 未处理分页查询
  const selectHandler = () => {
    pagination2.page = 1
    loadings.value = true
    doRefresh()
  }
  let cascaderRef = ref('')
  let configCascader = ref<{}>({
    corporateWidth: '230px', //公司宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: true, //部门是否必填
    size: 'small', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '公司', //公司label
    corporateNameLabelWidth: '65px', //选择公司label宽
    cascaderShow: 'sector', //配置部门不显示
  })
  const changeCascader = (data: any) => {
    const { corporateId } = data
    whList.value = []
    searchData.wh = ''
    searchData.firm = corporateId
    if (searchData.firm == undefined || searchData.firm == '') {
      whList.value = []
      return
    }
    whService.getWarhouseList(corporateId, '原纱仓')
  }
  let loadings = ref(false)
  const dataForm = reactive<ClothInfo>({
    id: null,
    dutymachineCode: '',
    machineCode: '',
    weaveCode: '',
    planOrderCode: '',
    greyCode: '',
    grayName: '',
    customName: '',
    storey: '',
    employeeId: '',
    employeeName: '',
    dutymachineDate: '',
    schedulStartDate: '',
    schedulEndDate: '',
    dutymachineStartDate: '',
    dutymachineEndDate: '',
    dutymachineState: 0,
    dispatchState: 0,
    monitorState: 0,
    monitor: '',
    obsoleteState: 0,
    deleteState: 0,
    remark: '',
    createName: '',
    createTime: '',
    updateName: '',
    updateTime: '',
    disassembleCode: '',
  })
  // 一表格准备事件
  const gridOption = ref()
  const colState = ref()
  const gridReady = (params: any) => {
    gridOption.value = params.api
    colState.value = params.columnApi
  }
  // 二表格准备事件
  const gridOption2 = ref()
  const colState2 = ref()
  const gridReady2 = (params: any) => {
    gridOption2.value = params.api
    colState2.value = params.columnApi
  }
  //已处理 未处理tab切换
  const changeTabs = (val: any) => {
    isIDs.value = val
    if (isIDs.value == 1) {
      pageData.dutymachineState = 0
      doRefresh()
    } else {
      pageData.dutymachineState = 1
      doRefresh2()
    }
  }
  //获取公司部门组列表
  const defaultColDef = {
    sortable: true,
    resizable: true,
    filter: true,
    // flex: 1
  }
  const whList = ref<any[]>([])
  const whService = new WHService()
  const whTypeList = whService.whTypeList
  const whTypeFieldList = whService.whTypeFieldList
  const companyList: any = whService.companyList
  const searchData = reactive<{
    whTypeName: string
    firm: string
    wh: string
    stats: any
  }>({
    firm: '',
    whTypeName: '',
    wh: '',
    stats: '',
  })
  // 公司下拉框 改变
  const companyChange = (val: any) => {
    whList.value = []
    searchData.wh = ''
    whService.getWarhouseList(val, '原纱仓')
  }
  const changeOption = (val: any) => {
    numList.printLs = ''
  }
  watch(
    () => whService.whList.value,
    (o, n) => {
      whList.value = whService.whList.value
    }
  )
  const corpSeeleFrim: any = ref()
  // 一表生成拆纱单
  const selectcsg = () => {
    if (gridOption.value.getSelectedRows().length == 0) {
      Message.error('请先勾选')
      return
    }
    //bumen pageData.ygName2 pageData.firmId2
    pageData.firmId2 = ''
    pageData.ygName2 = ''
    bumen.value = ''
    visiblecg.value = true
    corpSeeleFrim.value?.resetForm()
    pageData.firmId2 = userInfo.value.firmId
    console.log(userInfo.value.firmId);
  }
  const scrollbar = ref(true)
  let visiblecg = ref(false)
  let visiblecg1 = ref(false)
  let visiblecg2 = ref(false)
  let visiblecg3 = ref(false)
  let visiblecg5 = ref(false)
  let visiblecg6 = ref(false)
  let qrModal = ref<ModalDialogType | null>(null)
  let idDtaDy: any = ref({
    printNum: '',
  })
  let idDtaDys: any = ref({})
  let idDtaDys1: any = ref({})
  let idDtaDyss: any = ref([{}])
  // 打印拆纱单按钮
  // const print = () => {
  //     printJS({
  //         printable: 'dyy1',
  //         type: 'html',
  //         targetStyles: ['*'],
  //     })
  // }
  // 打印纱飞按钮
  const print1 = () => {
    visiblecg1.value = false
    visiblecg3.value = true
    printJS({
      printable: 'dyy3',
      type: 'html',
      targetStyles: ['*'],
    })
  }

  // 补打纱飞按钮
  const print2 = () => {
    // visiblecg5.value = false
    // visiblecg6.value = true
    printJS({
      printable: 'dyy5',
      type: 'html',
      targetStyles: ['*'],
    })
  }
  const prints2 = () => {
    var isListArray: any = []
    for (let item in pageData.idList) {
      isListArray.push(pageData.idList[item])
    }
    idDtaDys3.value.forEach(function (o: any) {
      o['printLs'] = String(isListArray)
    })
    //发请求
    // console.log(idDtaDys3.value, 'lllllllllllllllllllllllllll');
    post({
      url: 'planSingle/disassembleOrder/patchPrintSaFei',
      data: idDtaDys3.value,
    }).then(({ code, data, message }: any) => {
      if (code === 200) {
        //{001：[]}
        if (Object.keys(data).length != 0) {
          idDtaDyss.value = data
        }
        visiblecg5.value = false
        visiblecg6.value = true
      }
    })
  }
  const gbModal = () => {
    qrModal.value?.toggle()
  }
  // 二表打印拆纱单
  const dycsds = (item: any) => {
    // console.log(item, 'rrrrrrrrrrrrrrrrrrrrrrrrrrrrrr');
    if (gridOption2.value.getSelectedRows().length == 0) {
      Message.error('请先勾选')
      return
    }
    //1 拿到后段需要的传参
    let list: any = []
    idDtaDys.value = []
    gridOption2.value.getSelectedRows().forEach(function (o: any) {
      list.push(o['disassembleCode'])
    })
    //发请求
    post({
      url: 'planSingle/disassembleOrder/getListByDisassembleCode',
      data: list,
    }).then(({ code, data, message }: any) => {
      if (code === 200) {
        //{001：[]}
        if (Object.keys(data).length != 0) {
          idDtaDys.value = data
        }
        visiblecg.value = true
        // console.log(idDtaDys.value, 'ddddddddddddddddddddddd');
      }
    })
  }
  let idDtaDys2: any = ref([])
  let idList: any = ref([])
  // 二表打印纱飞
  const dysfs = () => {
    if (gridOption2.value.getSelectedRows().length == 0) {
      Message.error('请先勾选')
    } else {
      idDtaDys2.value = []
      gridOption2.value.getSelectedRows().forEach(function (o: any) {
        let uidd = {}
        uidd['planOrderCode'] = o.planOrderCode
        uidd['machineCode'] = o.machineCode
        uidd['planMaterialCode'] = o.planMaterialCode
        uidd['id'] = o.id
        uidd['printNum'] = 0
        idDtaDys2.value.push(uidd)
        idList.value.push(uidd)
      })
      // console.log(idDtaDys2.value, '9898998989898989');
      visiblecg1.value = true
    }
  }
  // 二表补打纱飞
  const idDtaDys3: any = ref([])
  const bdsfs = () => {
    if (gridOption2.value.getSelectedRows().length == 0) {
      Message.error('请先勾选')
    } else {
      idDtaDys3.value = []
      gridOption2.value.getSelectedRows().forEach(function (o: any) {
        let uidd: any = {}
        uidd['planOrderCode'] = o.planOrderCode
        uidd['machineCode'] = o.machineCode
        uidd['planMaterialCode'] = o.planMaterialCode
        uidd['id'] = o.id
        uidd['printLs'] = ''
        idDtaDys3.value.push(uidd)
      })
      visiblecg5.value = true
    }
  }
  let numList: any = ref([])
  const focusNum = (ids: any) => {
    let list = idList.value.filter(function (o: any) {
      return o['id'] == ids
    })
    if (list.length > 0) {
      numList.value = []
      for (let i = 1; i <= list[0]['printNum']; i++) {
        let ob: any = {}
        ob['printLs'] = i
        ob['id'] = list[0]['id']
        numList.value.push(ob)
      }
    }
  }
  //查询所有员工
  function getAllNickname(val: any) {
    // post({
    //   url: 'org/employee/getList',
    //   data: {
    //     groupId: pageData.firmId2,
    //     empName: val,
    //   },
    // }).then((res) => {
    //   if (res.code == 200) {
    //     pageData.ygNameList2 = res.data
    //   } else {
    //     Message.error({
    //       content: '查询员工名称失败',
    //       duration: 5000,
    //     })
    //   }
    // })
  }

  //获取员工名称
  const getYgName = () => {
    // post({
    //     url: '/hr/employee/getWorkingEmployeeListByCompanyIdAndPostId',
    //     data: {
    //         companyId: pageData.firmId,
    //         postId: pageData.ygType
    //     },
    // }).then(res => {
    //     if (res.code == 200) {
    //         pageData.ygNameList = JSON.parse(res.data)
    //     } else {
    //         Message.error({
    //             content: "查询员工名称失败",
    //             duration: 5000,
    //         });
    //     }
    // })
    //getAllNickname('')
    getyuangong()
  }
  function Isok() {
    localStorage.setItem('aaa', JSON.stringify(gridOption.value.getSelectedRows()))
    var codelist = [] as any
    gridOption.value.getSelectedRows().map((o: any, index: any) => {
      codelist[index] = o.disassembleCode
    })
    codelist.filter((item: any, index: any) => codelist.indexOf(item) === index)
    //localStorage.setItem("29999999",JSON.stringify(pageData.newlist))
    //localStorage.setItem("49999999",JSON.stringify(codelist))
    post({
      url: '/planSingle/disassembleEmployee/saveEmp',
      data: {
        codeList: codelist,
        empList: pageData.newlist,
      },
    }).then((res) => {
      if (res.code == 200) {
        Message.success({
          content: res.message,
          duration: 5000,
        })
        if (isIDs.value == 1) {
          pagination.page = 1
          doRefresh()
        } else {
          pagination2.page = 1
          doRefresh2()
        }
      } else {
        Message.error({
          content: res.message,
          duration: 5000,
        })
      }
    })
    visiblecg.value = false
  }
  const handleOk = () => {}
  const prints = () => {
    // idDtaDys1.value = []
    // //发请求
    // post({
    //     url: "planSingle/disassembleOrder/printSaFei",
    //     data: idDtaDys2.value
    // }).then(({ code, data, message }: any) => {
    //     if (code === 200) {
    //         //{001：[]}
    //         if (Object.keys(data).length != 0) {
    //             idDtaDys1.value = data
    //         }
    //         visiblecg1.value = false
    //         visiblecg3.value = true
    //     }
    // });
  }
  const print = () => {
    //console.log(44444)
  }
  const aaa = () => {
    //console.log(pageData.ygName2,'1213')
  }
  const baocun = () => {
    // console.log('------22222')
  }
  const getempname = (value: any) => {
    var shuzu = [] as any
    if (value.includes(0)) {
      pageData.ygName2 = pageData.ygNameList2
        .filter((option) => option.id !== 0)
        .map((option) => option.id)
    }
    pageData.ygNameList2.map((o: any) => {
      pageData.ygName2.map((d: any) => {
        if (o.id == d) {
          var obj = { empId: o.id, empName: o.name, empCode: o.code }
          shuzu.push(obj)
        }
      })
    })
    pageData.newlist = shuzu
    pageData.newlist.filter((item, index) => pageData.newlist.indexOf(item) === index)
  }
  const getempname2 = (value: any) => {
    if (value.includes('0#全选#')) {
      pageDataCS.ygName = pageDataCS.ygNameList
        .filter((option) => option.id !== 0)
        .map((x) => x.id + '#' + x.name + '#' + x.code)
    } else {
      pageDataCS.ygName = value.filter((option) => option !== '0#全选#')
    }
  }
  const visiblediolog = ref(false)
  const audit = () => {
    if (gridOption2.value.getSelectedRows().length === 0) {
      Message.error('请勾选需要审核的数据')
      return
    }
    visiblediolog.value = true
  }
  const fanshen = (record: any) => {
    localStorage.setItem('qqqqqqq', JSON.stringify(record))

    post({
      url: '/planSingle/disassembleEmployee/updateStateEmp',
      data: {
        codeList: [record.disassembleCode],
        empState: 1,
      },
    }).then((res) => {
      if (res.code == 200) {
        Message.success({
          content: res.message,
          duration: 5000,
        })
      } else {
        Message.error({
          content: res.message,
          duration: 5000,
        })
      }
    })
    doRefresh2()
  }
  const tanshenhe = () => {
    var org5 = []
    gridOption2.value.getSelectedRows().map((o: any) => {
      org5.push(o.disassembleCode)
    })
    localStorage.setItem('wwwwww', JSON.stringify(gridOption2.value.getSelectedRows()))
    post({
      url: '/planSingle/disassembleEmployee/updateStateEmp',
      data: {
        codeList: org5,
        empState: 2,
      },
    }).then((res) => {
      if (res.code == 200) {
        Message.success({
          content: res.message,
          duration: 5000,
        })
      } else {
        Message.error({
          content: res.message,
          duration: 5000,
        })
      }
    })
    doRefresh2()
  }

  const localeText1: any = ref(localeText)
  const pagingList1: any = ref(pagingList)
  const changeFrim = () => {
    bumen.value = ''
    pageData.ygName2 = []
    huoqubumen()
  }
  const gongsi = ref('')
  const gongsilist = ref([])
  const bumen = ref('')
  const bumenlist = ref([])
  const huoqubumen = () => {
    post({
      url: 'org/baCompany/getDepartmentTree?companyId=' + pageData.firmId2,
    }).then((res) => {
      if (res.code == 200) {
        bumenlist.value = res.data
      } else {
        Message.error({
          content: res.message,
          duration: 5000,
        })
      }
    })
  }
  const getbumen = () => {
    huoqubumen()
  }
  const changebumen = () => {
    pageData.ygName2 = []
    getyuangong()
  }
  const getyuangong = () => {
    if (!pageData.firmId2 || !bumen.value) {
      Message.warning('请先选择公司部门')
      return
    }
    post({
      url: 'org/hrEmployee/getUserAndSecondment',
      data: {
        department_id: bumen.value,
        workTime: dayjs().format('YYYY-MM-DD'),
      },
    }).then((res) => {
      if (res.code == 200) {
        pageData.ygNameList2 = res.data
        if (pageData.ygNameList2.length > 0) {
          pageData.ygNameList2.unshift({
            id: 0,
            name: '全选',
          })
        }
      } else {
        Message.error({
          content: res.message,
          duration: 5000,
        })
      }
    })
  }

  let configCascader1 = ref<{}>({
    corporateWidth: '570px', //公司宽度
    corporateRquired: false, //公司是否必填
    sectorRquired: false, //部门是否必填
    size: 'large', //选择框大小'mini' | 'small' | 'medium' | 'large'
    corporateName: '公司', //公司label
    corporateNameLabelWidth: '180px', //选择公司label宽
    cascaderShow: 'sector', //配置部门不显示
    defaultCorporateVal:''
  })
  const changeCascader1 = (data: any) => {
    const { corporateId } = data
    bumen.value = ''
    pageData.ygName2 = ''
    pageData.firmId2 = corporateId
  }

  const pageDataCS = reactive({
    show: false,
    caishadanhao: '',
    ygName: [],
    ygNameList: [],
    data: {},
  })

  const getYgNameCS = () => {
    post({
      url: 'org/hrEmployee/getUserAndSecondment',
      data: {
        department_id: 667,
        workTime: dayjs().format('YYYY-MM-DD'),
      },
    }).then((res) => {
      if (res.code == 200) {
        pageDataCS.ygNameList = res.data
        if (pageDataCS.ygNameList.length > 0) {
          pageDataCS.ygNameList.unshift({
            id: 0,
            name: '全选',
            code: '',
          })
        }
      } else {
        Message.error({
          content: res.message,
          duration: 5000,
        })
      }
    })
  }

  const Isok2 = () => {
    post({
      url: 'planSingle/disassembleEmployee/updateEmpInfo',
      data: {
        disassembleCode: pageDataCS.caishadanhao,
        empList: pageDataCS.ygName.map((z: any) => {
          return {
            empId: Number(z.split('#')[0]),
            empName: z.split('#')[1],
            empCode: z.split('#')[2],
          }
        }),
      },
    }).then((res: any) => {
      if (res.code == 200) {
        Message.success(res.message)
        doRefresh2()
        pageDataCS.show = false
      } else {
        Message.error(res.message)
      }
    })
  }
  const { saveGridState: saveGridState01, updateGridState: updateGridState01 } =
    saveOrUpdateGridState01('YarnStripPingDatasTypeIn-1', gridOption, colState, tc1)
  const onColumnMoved = () => {
    saveGridState01()
  }
  const onColumnResized = () => {
    saveGridState01()
  }
  const onColumnVisible = () => {
    saveGridState01()
  }
  const { saveGridState: saveGridState02, updateGridState: updateGridState02 } =
    saveOrUpdateGridState02('YarnStripPingDatasTypeIn-2', gridOption2, colState2, tc2)
  const onColumnMoved2 = () => {
    saveGridState02()
  }
  const onColumnResized2 = () => {
    saveGridState02()
  }
  const onColumnVisible2 = () => {
    saveGridState02()
  }
</script>
<style scoped lang="less">
  #Table td,
  #Table th {
    border: 1px solid #ccc;
    padding: 10px;
  }

  .tdStyle {
    min-width: 100px;
  }

  .notClick {
    background-color: gray;
    cursor: no-drop;
  }

  .isTable {
    margin-top: 100px;
    width: 90%;
    margin: 0 auto;
    border: 1.2px solid #ccc;
    text-align: center;
    border-collapse: collapse;

    td {
      border: 1.2px solid #ccc;
    }

    th {
      border: 1.2px solid #ccc;
    }
  }

  .isTable1 {
    margin: 50px;
    width: 90%;
    // margin: 0 auto;
    border: 1.2px solid #ccc;
    text-align: center;
    border-collapse: collapse;

    td {
      border: 1.2px solid #ccc;
    }

    th {
      border: 1.2px solid #ccc;
    }
  }

  .dyss {
    margin-bottom: 100px;
    display: flex;
    width: 90%;
    margin: 0 auto;
    justify-content: space-between;
    font-weight: 1000;

    div {
      width: 200px;
    }
  }
</style>
